//
//  HTStatusCell.swift
//  WeiBoDemo
//
//  Created by 郝涛 on 16/4/21.
//  Copyright © 2016年 郝涛. All rights reserved.
//

import UIKit
import SnapKit
class HTStatusCell: UITableViewCell {

    //记录底部toolBar的约束
    var toolBarConstraint:Constraint?
    
    
    //定义属性接收值
    var status:HTStatus?{
        didSet{
            
            //给原创微博赋值
           OriginalView.status = status
            
            //在重新给toolBar设置约束的时候需要卸载以前的约束
            self.toolBarConstraint?.uninstall()
            //没有转发微博
//            retweeted_status
            if status?.retweeted_status == nil{
                //没有就隐藏
                retweetView.hidden = true
                
              //toolBar的顶部 = 原创的底部
              ToolBarView.snp_makeConstraints(closure: { (make) -> Void in
                
               self.toolBarConstraint = make.top.equalTo(OriginalView.snp_bottom).constraint
                
              })
                self.ToolBarView.status = status
                
            }else{
              //有转发微博
                //显示
                retweetView.hidden = false
                // 设置数据
                retweetView.status = status
//                toolBar的顶部 = 转发的底部
                ToolBarView.snp_makeConstraints(closure: { (make) -> Void in
                    
                    self.toolBarConstraint = make.top.equalTo(retweetView.snp_bottom).constraint
                })
                
            }
        }
        
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    

        //设置视图
    private func setupUI(){
    
       contentView.addSubview(OriginalView)
        contentView.addSubview(ToolBarView)
        contentView.addSubview(retweetView)
        //设置约束
        //原创
        OriginalView.backgroundColor = UIColor.whiteColor()
        OriginalView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView).offset(8)
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
//            make.height.equalTo(50)
            
        }
        //底部
        ToolBarView.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.equalTo(contentView)
            make.height.equalTo(37)
          self.toolBarConstraint = make.top.equalTo(retweetView.snp_bottom).constraint
        }
        contentView.snp_makeConstraints { (make) -> Void in
            make.leading.trailing.top.equalTo(self)
            make.bottom.equalTo(ToolBarView)
        }
        retweetView.backgroundColor = UIColor.whiteColor()
        retweetView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(OriginalView.snp_bottom)
            make.leading.trailing.equalTo(contentView)
//            make.height.equalTo(150)
        }
        
    }

    
    //懒加载控件
   private lazy var OriginalView: HTStatusOriginalVIew = HTStatusOriginalVIew()
    
    //底部转发评论赞
    private lazy var ToolBarView:HTStatusToolBarView = HTStatusToolBarView()
    
    //转发微博
    private lazy var retweetView:HTStatusRetweetView = HTStatusRetweetView()
}


